function Cloud(cxt,sx,ex,sy,ey,spd,freq) {
	
	var cloudPool = new Array();
	var cloud = new Array();
	var context = cxt;
	var MAX_cloud_POOL = 100;
	var starty = sy;
	var endy = ey;
	var startx = sx;
	var endx = ex;
	var speed = spd;
	var frequency = freq;
	var cloudImage;
	var cloudImage = new Image();
	cloudImage.onload = this.imageLoaded;
	cloudImage.src = "cloud.gif";
	var createWait = 10;
	var createWaitCount = 10;
	
	this.draw = function() {
	
		var rnd =Math.floor(Math.random() * 100);
		//Debugger.log("draw cloud:" +	 rnd);
		var rndx =Math.floor(Math.random() * (endx-startx)) + startx;
		//var rndx =Math.floor(Math.random() * endx);
		createWaitCount++;
		if (rnd < frequency  && createWaitCount >= createWait) {
			createWaitCount = 0;
			Debugger.log("CREATE cloud");
			if (cloudPool.length > 0) {
				var tempcloud = cloudPool.pop();
				tempcloud.x = rndx;
				tempcloud.y = starty;
				tempcloud.image = "cloud.gif";
				cloud.push(tempcloud);
			} else {
				cloud.push({x:rndx,y:starty,image:"cloud.gif"});
			}	
		}
		
		for (var i=cloud.length-1; i>= 0;i--) {;
			cloud[i].y += speed;
			//Debugger.log(cloud.y)
			
			if (cloud[i].y >= endy ) {
				if (cloudPool.length < MAX_cloud_POOL) {
					cloudPool.push(cloud.splice(i,1));
				} else {
					cloud.splice(i,1);
				}
			} else {
				context.globalAlpha = .4;
				context.drawImage(cloudImage,cloud[i].x,cloud[i].y);
				context.globalAlpha = 1;
			}
			
		}
	}

}
